<template>
	<view class="print_list">
		<view class="p_flex">
			<image src="https://dy.sykj365.com/uploads/mini/weixuanzhong@2x.png" class="p_img_48 p_margin_r_24" v-if="!item.choose"
				@click="$emit('getChoose', index)">
			</image>
			<image src="https://dy.sykj365.com/uploads/mini/xuanzhong@2x.png" class="p_img_48 p_margin_r_24" v-else
				@click="$emit('getIsChoose', index)"></image>
			<view class="p_flex_2 p_flex">
				<image src="https://dy.sykj365.com/uploads/mini/file@2x.png" class="p_img_64 p_margin_r_16"
					v-if="getTypeName(item) === 'pdf'"></image>
				<image src="https://dy.sykj365.com/uploads/mini/word.png" class="p_img_64 p_margin_r_16"
					v-if="getTypeName(item) === 'word'"></image>
				<image src="https://dy.sykj365.com/uploads/mini/ppt.png" class="p_img_64 p_margin_r_16" v-if="getTypeName(item) === 'ppt'">
				</image>
				<view class="p_flex_2">
					<view class="p_flex2">
						<view class="p_font_32 p_flex_1 p_one_text">{{item.name}}</view>
						<image src="https://dy.sykj365.com/uploads/mini/shanchu1@2x.png" class="p_img_32 p_margin_l_30" v-if="deleteState"
							@click="$emit('getDelView', item)">
						</image>
					</view>
					<view class="p_font_24 p_color_b2 p_margin_t_8" v-if="!item.paper">
						请设置打印参数
					</view>
					<view class="p_font_24 p_color_b2 p_margin_t_8" v-else>
						{{item.brand}}/{{item.paper}}/{{item.colour}}/{{getD(item.single_double)}}/{{item.binding_type}}{{getType(item)}}{{item.reduction_printing?'/' + item.reduction_printing: ''}}/{{item.num}}份{{item.print_range?'/' + item.print_range: ''}}
					</view>
					<view class="p_flex9 p_margin_t_16" v-if="item.paper">
						<view class="p_font_28 p_color_ff5555"><text
								class="p_font_20 p_margin_r_8">¥</text>{{(Number(item.price) * Number(item.num)).toFixed(2)}}
						</view>
						<view class="print_num">
							<image src="https://dy.sykj365.com/uploads/mini/jian@2x.png" class="p_img_52"
								@click="$emit('getChooseNum', {type: 0, index: index})"></image>
							<view class="p_font_28">
								<input type="number" v-model="itemNum" @blur="getBlur" />
							</view>
							<image src="https://dy.sykj365.com/uploads/mini/jia3@2x.png" class="p_img_52"
								@click="$emit('getChooseNum', {type: 1, index: index})"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="p_flex9 p_margin_t_48">
			<view class="p_font_20 p_color_b2 p_flex2" v-if="item.information == 1">
				<view class="fuhao">!</view>资料属于标准定制物，使用统一格式打印
			</view>
			<view v-else></view>
			<view class="p_flex2">
				<view class="print_btn2" @click="getLookFile(item.file)" v-if="item.information == 0">预览</view>
				<view class="print_btn1" @click="getLink" v-if="item.information != 2">
					{{item.information == 0?'打印设置': '查看详情'}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: {}
			},
			deleteState: {
				type: Boolean,
				default: false
			},
			index: {
				type: String,
				default: ''
			},
		},
		data() {
			return {
				itemNum: 0,
			}
		},
		created() {
			this.itemNum = this.item.num;
		},
		watch: {
			item(newVal, oldVal) {
				this.itemNum = this.item.num;
			}
		},
		methods: {
			getD(e) {
				if (e == 0) return '单面';
				if (e == 1) return '双面';
				if (e == '') return '';
			},
			getType(item) {
				let t_ = [];
				let s_ = '';
				if (item.cover_type) t_.push(item.cover_type)
				if (item.film_covering) t_.push(item.film_covering)

				if (t_.length > 0) {
					s_ = (t_.join('·'))
				}

				return s_
			},
			getLink() {
				let self = this;
				if (self.item.information == 0) {
					getApp().getNavigateTo('/pages/index/set?item=' + encodeURIComponent(JSON.stringify(self.item)))
				} else {
					getApp().getNavigateTo('/pages/dataBank/detail?id=' + self.item.information_id)
				}
			},
			getBlur() {
				let i_ = this.index;
				let n_ = this.itemNum;

				this.$emit('getChooseNum', {
					type: 2,
					index: i_,
					event: n_
				})

				if (this.itemNum === '' || this.itemNum == '0') {
					this.itemNum = 1;
				}
			},
			getLookFile(file) {
				let self = this;
				getApp().getSeeFile(file);
			},
			getTypeName(e) {
				if (!e.source_file) {
					return 'pdf'
				}

				let arr_ = e.source_file.split('.');
				if (arr_[arr_.length - 1] === 'docx' || arr_[arr_.length - 1] === 'doc') {
					return 'word'
				}
				if (arr_[arr_.length - 1] === 'pptx' || arr_[arr_.length - 1] === 'ppt') {
					return 'ppt'
				}
			}
		},
	}
</script>

<style lang="less">
	.print_list {
		padding: 32rpx;
		margin: 32rpx 0;
		background-color: #fff;
		border-radius: 16rpx;
	}

	.print_num {
		display: flex;
		align-items: center;
		background-color: #f3f3f3;

		view {
			width: 80rpx;
			text-align: center;
		}
	}

	.print_btn1 {
		color: #05B570;
		width: 152rpx;
		height: 52rpx;
		border-radius: 80rpx;
		box-sizing: border-box;
		border: 1px solid #05B570;
		font-size: 26rpx;
		line-height: 36rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-left: 16rpx;
	}

	.print_btn2 {
		color: #7A7A7A;
		width: 100rpx;
		height: 52rpx;
		border-radius: 80rpx;
		box-sizing: border-box;
		border: 1px solid #E8E8E8;
		font-size: 26rpx;
		line-height: 36rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.fuhao {
		color: #B2B2B2;
		width: 20rpx;
		height: 20rpx;
		border: 1px solid #B2B2B2;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 10rpx;
	}
</style>
